import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.sql.*;
//the delHome servlet allows the user to remove a home from the database
//the delHome servlet is called from the view homes from, the market form, and the house details form
public class delHome extends HttpServlet
{
	public static dbapi conn;
	public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException,IOException
	{
		response.setContentType("text/html");
		PrintWriter out = response.getWriter();
		//New dbapi instance
		conn = new dbapi();
		//Connect to Oracle
		conn.connect();
		out.println(htmlHeader.header);
		if(!conn.connected)//if can't connect, output error message
		{
			out.println("CANT CONNECT! <br>");
			out.println(conn.msg + "<br>");
			return;
		}
		int houseID = Integer.parseInt(request.getParameter("id"));
		boolean worked = conn.delHome(houseID);//creates a boolean variable called worked that notes whether or not the delhome function worked
		
		if (!worked)//if delete home didn't work, output error message
		{
			out.println(conn.msg);
		}else{//else, inform the user that the add was successful and refresh to the homes list form
			out.println("<header><meta http-equiv=\"refresh\" content=\"2;getHouses\"></header><body><p>Removed House Successfully...<p></body>");
		}
		
		return;
	}
}
